public class FifthQtnThread {
    private static int ticket=100;


    public static void ByTicket(){
        ticket--;
        if (ticket>0){
        System.out.println(Thread.currentThread().getName()+"卖出一张票,余票为："+ticket);
        }else {
            System.out.println("票已经卖完了");
            System.exit(1);
        }
    }

    public static void main(String[] args) {

        for (int i = 1; i <=5; i++) {
            new Thread(()->{
                while (true){
                    ByTicket();
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            },"第"+i+"检票口").start();
        }
    }
}
